import * as React from 'react';
import { Redirect } from 'umi';

export default (props: any) => {
  const { children, routes, location } = props;
  const findUrl = (routes: any, location: any) => {
    for (let i = 0; i < routes.length; i++) {
      if (routes[i].path === location.pathname) {
        return true;
      }
      if (routes[i].routes && findUrl(routes[i].routes, location)) {
        return true;
      }
    }
    return false;
  };
  if (!findUrl(routes, location)) {
    return <Redirect to='/404' />;
  }
  return <div>{children}</div>;
}
